package ui;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

import data.LoadData;
import data.TimeStock;

public class ContentProvider  implements IStructuredContentProvider {
	public Object[] getElements(Object inputElement) {
		
		synchronized(inputElement){
			@SuppressWarnings("unchecked")
			LinkedHashSet<String> codeVector = (LinkedHashSet<String>)inputElement;
			TimeStock[] ts = null;
			List<TimeStock> tss = new ArrayList<TimeStock>();
			for (Iterator<String> iterator = codeVector.iterator(); iterator.hasNext();){
				String code = iterator.next();
				TimeStock timeStock=LoadData.getTimeStock(code);
				if(timeStock!=null){
					tss.add(timeStock);
				}
			}
			ts = tss.toArray(new TimeStock[tss.size()]);
			return ts;
		}
	}
	public void dispose() {
	}
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}
}
